package com.compass.doctor.service;

import static android.app.PendingIntent.FLAG_IMMUTABLE;

import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.IBinder;

import androidx.annotation.Nullable;

import com.compass.doctor.R;
import com.compass.doctor.ui.MainActivity;
import com.compass.framework.utils.LogUtil;

/**
 * Description： 前台服务
 * Date:2024/11/6 13:41
 */
public class ForegroundService extends Service {

    @Override
    public void onCreate() {
        super.onCreate();
        LogUtil.INSTANCE.d("LocalRecordingService=====onCreate");

    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        LogUtil.INSTANCE.d("LocalRecordingService=====onStartCommand");

        Notification.Builder builder = new Notification.Builder(this.getApplicationContext()); //获取一个Notification构造器
        Intent nfIntent = new Intent(this, MainActivity.class);
        int flagsV = 0;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            flagsV = PendingIntent.FLAG_IMMUTABLE;
        } else {
            flagsV = PendingIntent.FLAG_UPDATE_CURRENT;
        }

        builder.setContentIntent(PendingIntent.getActivity(this, 0, nfIntent, flagsV)) // 设置PendingIntent
                .setLargeIcon(BitmapFactory.decodeResource(this.getResources(),
                        R.mipmap.app_logo)) // 设置下拉列表中的图标(大图标)
                .setContentTitle("岐黄中医") // 设置下拉列表里的标题
                .setSmallIcon(R.mipmap.ic_logo) // 设置状态栏内的小图标
                .setContentText("岐黄中医正在运行") // 设置上下文内容
                .setWhen(System.currentTimeMillis()); // 设置该通知发生的时间
        Notification notification = builder.build(); // 获取构建好的Notification
        notification.defaults = Notification.DEFAULT_SOUND; //设置为默认的声音


        return super.onStartCommand(intent, flags, startId);
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
}
